


clear
capture log close
set more off



***  changing ratio

clear
local yrover 1990 1993 1997 2001 2005 2009 2015 
 
foreach i of local yrover  {
clear
use recs_1990
capture drop if kwh==999999
qui drop if moneypy==.
qui egen sumhh=total(nweight)
qui gen weight=nweight/sumhh

collapse (sum) weight,by(moneypy)

quietly drop if moneypy==. 
rename moneypy hhfaminc_1990
sort hhfaminc_1990 
quietly destring hhfaminc_1990,replace

quietly merge 1:1 hhfaminc_1990 using  conspchange_1990 
capture rename meanincome income1990
drop _merge
quietly merge 1:1 hhfaminc_1990  using  conspchange_`i'.dta
gen predicted=meankwh/meanincome*income1990

quietly sum predicted[aweight=weight]
quietly return list
dis `i',r(mean)

}


***** changing income
clear
local yrover 1990 1993 1997 2001 2005 2009 2015 
 
foreach i of local yrover  {
clear

use recs_1990
capture drop if kwh==999999
qui drop if moneypy==.
qui egen sumhh=total(nweight)
qui gen weight=nweight/sumhh

collapse (sum) weight,by(moneypy)
rename moneypy hhfaminc_1990

qui merge 1:1 hhfaminc_1990 using conspchange_1990.dta

gen e_i=meankwh/meanincome 
drop meankwh meanincome

qui drop _merge
quietly merge 1:1 hhfaminc_1990 using  conspchange_`i'.dta 
drop _merge


gen predicted=e_i*meanincome

quietly sum predicted[aweight=weight]
quietly return list
dis `i',r(mean)
}




